﻿using System;
using System.Globalization;
using Cfg.ConfigValues;
using Cfg.Exceptions;
using NUnit.Framework;

namespace Cfg.Test
{
    [TestFixture]
    public class ObjectTest
    {
        public class Foo
        {

        }

        public class Bar : ConfigValueBase
        {
            public override void Parse()
            {

            }
        }

        public class Far
        {
            public string Val { get; set; }
        }

        [Test]
        public void GetObjectWithCustomParser()
        {
            AppSettings.Settings.AddParser(x => new Far {Val = x});

            AppSettings.Settings.AddParser(x => new CultureInfo(x));

            var vb = new ValueBuilder(typeof (Far), "pla");
            var value = (Far)vb.GetValue();

            Assert.AreEqual("pla", value.Val);
        }

        [Test]
        [ExpectedException(typeof (InvalidFormatException))]
        public void GetValueWithoutIParseable()
        {
            var cv = new ValueBuilder(typeof (Foo), "pla");
            Console.WriteLine(cv.GetValue());
        }

        [Test]
        public void GetValueWithIParseable()
        {
            var cv = new ValueBuilder(typeof (Bar), "pla");
            Console.WriteLine(cv.GetValue());
        }
    }
}